//
//  CALayer+Addition.m
//  dingding
//
//  Created by dingding on 15/12/10.
//  Copyright © 2015年 dingding. All rights reserved.
//
#import "NSMutableDictionary+AllType.h"

@implementation NSMutableDictionary(AllType)

-(void)putInt:(int)data key:(NSString*)key;
{
    NSString* str=[NSString stringWithFormat:@"%d",data];
    [self setObject:str forKey:key];
}

-(void)putStr:(NSString*)data key:(NSString*)key;
{
    if(data)
    [self setObject:data forKey:key];
}

-(void)putDouble:(double)data key:(NSString*)key;
{
    NSString* str=[NSString stringWithFormat:@"%f",data];
    [self setObject:str forKey:key];
}

-(void)putFloat:(float)data key:(NSString*)key;
{
    NSString* str=[NSString stringWithFormat:@"%f",data];
    [self setObject:str forKey:key];
}

-(void)putBool:(BOOL)data key:(NSString *)key
{
    NSString* str=[NSString stringWithFormat:@"%d",data?1:0];
    [self setObject:str forKey:key];
}

-(void)putLong:(long long)data key:(NSString*)key
{
    NSString* str=[NSString stringWithFormat:@"%lld",data];
    [self setObject:str forKey:key];
}

-(void)putArray:(NSArray*)array key:(NSString*)key
{
    if(array)
    [self setObject:array forKey:key];
}


-(int)getInt:(NSString*)key
{
   NSString* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return [tmp intValue];
    }
    return -9999;
}

-(NSString*)getStr:(NSString*)key
{
    NSObject *object=[self objectForKey:key];
    NSString* tmp;
    if ( [object isKindOfClass:[NSNumber class]])
    {
        tmp = [(NSNumber*)object stringValue];
    }
    else if ([object isKindOfClass:[NSString class]])
    {
        tmp = (NSString*)object;
    }
    if(tmp&&![tmp isEqual:[NSNull null]]&&![tmp isEqualToString:@""]){
        return tmp;
    }
    return nil;
}

-(double)getDouble:(NSString*)key
{
    NSString* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return [tmp doubleValue];
    }
    return 0;
}

-(float)getFloat:(NSString*)key
{
    NSString* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return [tmp floatValue];
    }
    return 0;
}

-(BOOL)getBool:(NSString*)key
{
    NSString* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return [tmp intValue]==1;
    }
    return NO;
}

-(long long)getLong:(NSString*)key
{
    NSString* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return [tmp longLongValue];
    }
    return 0;
}

-(NSObject*)getObject:(NSString*)key
{
    NSObject* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return tmp;
    }
    return nil;
}

-(NSDictionary*)getDict:(NSString*)key
{
    NSObject* tmp=[self objectForKey:key];
    if(tmp&&[tmp isKindOfClass:[NSDictionary class]]){
        return (NSDictionary*)tmp;
    }
    return nil;
}

@end

@implementation NSDictionary(AllType)

-(int)getInt:(NSString*)key
{
    NSString* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return [tmp intValue];
    }
    return -9999;
}

-(NSString*)getStr:(NSString*)key
{
    NSObject *object=[self objectForKey:key];
    NSString* tmp;
    if ( [object isKindOfClass:[NSNumber class]])
    {
        tmp = [(NSNumber*)object stringValue];
    }
    else if ([object isKindOfClass:[NSString class]])
    {
        tmp = (NSString*)object;
    }
    if(tmp&&![tmp isEqual:[NSNull null]]&&![tmp isEqualToString:@""]){
        return tmp;
    }
    return nil;                                                 
}

-(double)getDouble:(NSString*)key
{
    NSString* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return [tmp doubleValue];
    }
    return 0;
}

-(float)getFloat:(NSString*)key
{
    NSString* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return [tmp floatValue];
    }
    return 0;
}

-(BOOL)getBool:(NSString*)key
{
    NSString* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return [tmp intValue]==1;
    }
    return NO;
}

-(long long)getLong:(NSString*)key
{
    NSString* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return [tmp longLongValue];
    }
    return 0;
}

-(NSArray*)getArray:(NSString*)key
{
    NSArray* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return tmp;
    }
     return nil;
}

-(NSObject*)getObject:(NSString*)key
{
    NSObject* tmp=[self objectForKey:key];
    if(tmp&&![tmp isEqual:[NSNull null]]){
        return tmp;
    }
    return nil;
}

-(NSDictionary*)getDict:(NSString*)key
{
    NSObject* tmp=[self objectForKey:key];
    if(tmp&&[tmp isKindOfClass:[NSDictionary class]]){
        return (NSDictionary*)tmp;
    }
    return nil;
}

@end
